package oneD.models;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StreamTokenizer;

public class ModelReader {
	protected StreamTokenizer st_ = null;
	private InputStream is_;
	private String filePath_;

	public ModelReader(String filePath) {
		filePath_ = filePath;
		is_ = null;
		reset();
	}

	public boolean isReady() {
		return st_ != null;
	}

	protected void reset() {
		if (is_ != null)
			try {
				is_.close();
			} catch (IOException e) {
				System.out.println(e.toString());
			}

		try {
			is_ = new FileInputStream(this.filePath_);
		} catch (FileNotFoundException e) {
			System.out.println(e.toString());
		}

		if (is_ != null) {
			Reader r = new BufferedReader(new InputStreamReader(is_));
			st_ = new StreamTokenizer(r);
			st_.commentChar('#');
		}
	}
}
